package com.qianfeng.day1029;

import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.redisson.Redisson;
import org.redisson.config.Config;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
@EnableEurekaClient
public class Day1029Application {

    public static void main(String[] args) {
        SpringApplication.run(Day1029Application.class, args);
    }


    @Bean
    public Redisson getRedisson(){

        Config config = new Config();
        config.useSingleServer().setAddress("redis://192.168.75.135:6379").setPassword("root").setDatabase(0);
        return (Redisson)Redisson.create(config);
    }

    @Bean
    public CuratorFramework getZookeeper(){
        RetryPolicy retryPolicy = new ExponentialBackoffRetry(3000,2);


        CuratorFramework framework = CuratorFrameworkFactory.builder().connectString(
                "192.168.75.135:2181,192.168.75.135:2182,192.168.75.135:2183"
        ).retryPolicy(retryPolicy).build();

        framework.start();
        return  framework;
    }


}
